package com.poc.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.poc.integration.OrdemCompraGateway;
import com.poc.pojo.OrdemCompra;

@Controller
@RequestMapping(value="/data")
public class PocController {
	
	@Autowired
	private OrdemCompraGateway gateway;
	
	@RequestMapping(value = "/ordemCompra.action", method = RequestMethod.POST)
	public @ResponseBody Map<String, ? extends Object> test(OrdemCompra ordemCompra) {

		HashMap<String, Object> result = new HashMap<String, Object>();
		try {
			OrdemCompra ordem = gateway.aprovaOrdemCompra(ordemCompra);
			result.put("ordemCompra", ordem);
			result.put("sucess", true);
		} catch (Exception e) {

			result.put("sucess", false);
		}
		
		return result;
	}

	public OrdemCompraGateway getGateway() {
		return gateway;
	}

	public void setGateway(OrdemCompraGateway gateway) {
		this.gateway = gateway;
	}
}
